package com.longge;

import java.util.Comparator;
import java.util.HashMap;
import java.util.Map;

public class MaxFrequencyElements {

    public int maxFrequencyElements(int[] nums) {

        HashMap<Integer, Integer> map = new HashMap<>();

        for (int num : nums) {
            map.put(num, map.getOrDefault(num, 0) + 1);
        }

        Integer max = map.values().stream().sorted(Comparator.comparing(Integer::intValue).reversed()).findFirst().get();

        int ans = 0;
        for (Map.Entry<Integer, Integer> entry : map.entrySet()) {
            if (entry.getValue().equals(max)){
                ans+=entry.getValue();
            }
        }
        return ans;
    }
}
